//
//  LabelTableViewCell.m
//  NineGroupProject
//
//  Created by dllo on 15/12/24.
//  Copyright © 2015年 lushan. All rights reserved.
//

#import "LabelTableViewCell.h"
#import "UIImageView+WebCache.h"

@interface LabelTableViewCell ()
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *descriptionLabel;
@property (nonatomic, strong) UILabel *blueLabel;
@end

@implementation LabelTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews
{
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20 * WID, 20 * HEI)];
    [self.contentView addSubview:self.titleLabel];
    
    self.descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 30 * WID, 30 * HEI)];
    [self.contentView addSubview:self.descriptionLabel];
    
    self.blueLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
    [self.contentView addSubview:self.blueLabel];
    

}

-(void)setPlaceDetailModel:(PlaceDetailModel *)placeDetailModel{
    

    _placeDetailModel = placeDetailModel;
    
    self.titleLabel.frame = CGRectMake(30 * WID, 20 * HEI, WIDTH - 60 * WID, 30 * HEI);
    self.titleLabel.text = self.placeDetailModel.title;
    self.titleLabel.numberOfLines = 0;
    [self.titleLabel sizeToFit];
    self.titleLabel.font = [UIFont systemFontOfSize:17];
    
    self.blueLabel.frame = CGRectMake(self.titleLabel.frame.origin.x - 15 * WID, self.titleLabel.frame.origin.y, 5 * WID, self.titleLabel.frame.size.height);
    self.blueLabel.backgroundColor = [UIColor blueColor];
    
    self.descriptionLabel.text = self.placeDetailModel.detailDescription;
    self.descriptionLabel.frame = CGRectMake(15 * WID, self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height , WIDTH - 30 * WID, 1000);
    self.descriptionLabel.numberOfLines = 0;
    [self.descriptionLabel sizeToFit];
    self.descriptionLabel.font = [UIFont systemFontOfSize:15];
    
    CGFloat height = [LabelTableViewCell heightForContent:self.placeDetailModel.detailDescription];
    CGRect tempFrame = self.descriptionLabel.frame;
    tempFrame.size.height = height;
    self.descriptionLabel.frame = tempFrame;
    
    
}
+(CGFloat)heightForContent:(NSString *)content{
    CGSize size = CGSizeMake(WIDTH - 30 * WID, 10000);
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17.0],NSFontAttributeName, nil];
    CGRect frame = [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return frame.size.height;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
